package com.example.administrator.x3picturetransliteration.Base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * 用于ListView的公共适配器
 * 2018/10/9.
 */

public abstract class BaseListViewAdapter extends BaseAdapter {

    public Context context;
    private LayoutInflater inflater;

    public BaseListViewAdapter(Context context){

        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mCount();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        View mview = null;
        ViewHolder mViewHolder = null;

        if(view!=null){

            mview = view;
            mViewHolder = (ViewHolder)mview.getTag();

        }else {

            mview = inflater.inflate(getLayoutView(),null);
            mViewHolder = InstantiationView(mview);
            mview.setTag(mViewHolder);

        }

        logic(mViewHolder,mview,i);

        return mview;
    }

    /** 拿到布局资源id */
    public abstract int getLayoutView();

    /** 设置item的数量 */
    public abstract int mCount();

    /** 实现逻辑代码 */
    public abstract void logic(ViewHolder mViewHolder, View view, final int position);

    /** 实例化view */
    public abstract ViewHolder InstantiationView(View mview);

    /** ViewHolder */
    public abstract class ViewHolder{}

}
